package com.simon.hse.activity.danger;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.simon.hse.MyApplication;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.http.CommonCallBack;
import com.simon.hse.http.HttpManager;
import com.simon.hse.http.entity.DropDownInput;
import com.simon.hse.http.entity.DropDownOutput;
import com.simon.hse.http.entity.TrainPersonInput;
import com.simon.hse.http.entity.TrainPersonOutput;
import com.simon.hse.utils.ToastUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

@SuppressWarnings("all")
@ContentView(R.layout.activity_danger_manager)
public class DangerManagerActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTv_common_title.setText("隐患管理");

        initDepartment();
        initTrainPerson();
        initDays();
        initRates();
        initAreas();
        initStations();
        initStandards();
        initDangerClassify();
        initDangerLevel();
        initConditions();
        initRectifyState();
    }

    @Event(value = {R.id.iv_common_left})
    private void back(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
        }
    }

    @Event(value = {R.id.ll_function_1, R.id.ll_function_2, R.id.ll_function_3, R.id.ll_function_4, R.id.ll_function_5, R.id.ll_function_6})
    private void clickFunction(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.ll_function_1:
                intent.setClass(DangerManagerActivity.this, DangerEliminateActivity.class);
                break;
            case R.id.ll_function_2:
                intent.setClass(DangerManagerActivity.this, DangerReportActivity.class);
                break;
            case R.id.ll_function_3:
                intent.setClass(DangerManagerActivity.this, DangerApprovalActivity.class);
                break;
            case R.id.ll_function_4:
                intent.setClass(DangerManagerActivity.this, DangerRectifyActivity.class);
                break;
            case R.id.ll_function_5:
                intent.setClass(DangerManagerActivity.this, DangerAcceptingActivity.class);
                break;
            case R.id.ll_function_6:
                intent.setClass(DangerManagerActivity.this, DangerStopActivity.class);
                break;
        }
        startActivity(intent);
    }

    /**
     * 部门
     */
    private void initDepartment() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("9009");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("9009")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerDepartList.clear();
                            MyApplication.getInstance().mDangerDepartList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 班次
     */
    private void initDays() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("n51");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("n51")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerDaysList.clear();
                            MyApplication.getInstance().mDangerDaysList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 区域
     */
    private void initAreas() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("97");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("97")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerAreasList.clear();
                            MyApplication.getInstance().mDangerAreasList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 频次
     */
    private void initRates() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("6020");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("6020")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerRatesList.clear();
                            MyApplication.getInstance().mDangerRatesList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 岗位
     */
    private void initStations() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("60");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("60")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerStationsList.clear();
                            MyApplication.getInstance().mDangerStationsList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 标准类型
     */
    private void initStandards() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("101");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("101")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerStandardsList.clear();
                            MyApplication.getInstance().mDangerStandardsList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 排查情况
     */
    private void initConditions() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("115");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("115")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerConditionsList.clear();
                            MyApplication.getInstance().mDangerConditionsList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 整改状态
     */
    private void initRectifyState() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("6010");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("6010")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerStateList.clear();
                            MyApplication.getInstance().mDangerStateList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 隐患分类
     */
    private void initDangerClassify() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("100");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("100")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerClassifyList.clear();
                            MyApplication.getInstance().mDangerClassifyList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 隐患等级
     */
    private void initDangerLevel() {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add("03");
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        if (dataDicListBean.getKey().equals("03")) {
                            List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                            MyApplication.getInstance().mDangerLevelList.clear();
                            MyApplication.getInstance().mDangerLevelList.addAll(valueBeanList);
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 观察人 负责人
     */
    private void initTrainPerson() {
        TrainPersonInput trainPersonInput = new TrainPersonInput();
        TrainPersonInput.ModelBean modelBean = new TrainPersonInput.ModelBean();
        TrainPersonInput.ModelBean.SysUserInforBean sysUserInforBean = new TrainPersonInput.ModelBean.SysUserInforBean();
        modelBean.setSysUserInfor(sysUserInforBean);
        trainPersonInput.setModel(modelBean);
        trainPersonInput.setLimit(20);
        trainPersonInput.setOffset(0);

        Call<String> call = HttpManager.getInstance().requestService().TRAIN_PERSON(HttpManager.getInstance().requestBody(trainPersonInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                TrainPersonOutput trainPersonOutput = new Gson().fromJson(result, TrainPersonOutput.class);
                if (trainPersonOutput.getResult().equals("Success")) {
                    List<TrainPersonOutput.DataBean.PageDataBean> pageDataBeanList = trainPersonOutput.getData().getPageData();
                    MyApplication.getInstance().mListTrainPerson.clear();
                    MyApplication.getInstance().mListTrainPerson.addAll(pageDataBeanList);
                } else {
                    ToastUtils.getInstance().showShortToastBottom(trainPersonOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

}
